package com.szly.phm.admin.controller;


import com.szly.phm.admin.aspectj.annotation.OperationLogAnnotation;
import com.szly.phm.admin.aspectj.enums.ModuleEnum;
import com.szly.phm.admin.aspectj.enums.OperationActionEnum;
import com.szly.phm.admin.utils.CustomResponse;
import com.szly.phm.admin.utils.SecurityUtils;
import com.szly.phm.common.entity.dto.stu.*;
import com.szly.phm.common.entity.dto.user.LoginUserDTO;
import com.szly.phm.common.entity.result.RootResponse;
import com.szly.phm.common.service.IScService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-07-02
 */
@RestController
@Validated
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/pc/student")
@Api(tags = "学生管理")
public class SysStudentController {

    private final IScService scService;


//    @ApiOperation(value = "分页查询角色列表")
//    @GetMapping("/v1/roles")
//    public RootResponse queryRolePageV1(@Valid RolePageDTO roleDTO) {
//        return roleService.queryRolePage(roleDTO);
//    }


    @ApiOperation(value = "添加班级")
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/class")
    @CustomResponse
    public RootResponse createClass(@Valid @RequestBody CreateClassDTO createClassDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.createClass(createClassDTO,userDTO);
    }
    @ApiOperation(value = "添加专业")
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/majors")
    @CustomResponse
    public RootResponse createMajor(@Valid @RequestBody CreateMajorDTO createMajorDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.createMajor(createMajorDTO,userDTO);
    }
    @ApiOperation(value = "添加学生")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/students")
    public RootResponse createStudent(@Valid @RequestBody CreateStudentDTO createStudentDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.createStudent(createStudentDTO,userDTO);
    }
    @ApiOperation(value = "添加教学内容")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/teachDatas")
    public RootResponse createTeachData(@Valid @RequestBody CreateTeachDataDTO createTeachDataDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.createTeachData(createTeachDataDTO,userDTO);
    }
    @ApiOperation(value = "添加教学类型")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.SAVE)
    @PostMapping("/v1/teachDataTypes")
    public RootResponse createTeachDataType(@Valid @RequestBody CreateTeachDataTypeDTO createTeachDataTypeDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.createTeachDataType(createTeachDataTypeDTO,userDTO);
    }
    @ApiOperation(value = "修改班级")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/class")
    public RootResponse updateClass(@Valid @RequestBody UpdateClassDTO updateClass) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.updateClass(updateClass,userDTO);
    }
    @ApiOperation(value = "修改专业")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/majors")
    public RootResponse updateMajor(@Valid @RequestBody UpdateMajorDTO updateMajor) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.updateMajor(updateMajor,userDTO);
    }
    @ApiOperation(value = "修改学生")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/students")
    public RootResponse updateStudent(@Valid @RequestBody UpdateStudentDTO updateStudent) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.updateStudent(updateStudent,userDTO);
    }
    @ApiOperation(value = "修改教学内容")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/teachDatas")
    public RootResponse updateTeachData(@Valid @RequestBody UpdateTeachDataDTO updateData) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.updateTeachData(updateData,userDTO);
    }
    @ApiOperation(value = "修改教学类型")
    @CustomResponse
   @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @PutMapping("/v1/teachDataTypes")
    public RootResponse updateTeachDataType(@Valid @RequestBody UpdateTeachDataTypeDTO updateDataType) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.updateTeachDataType(updateDataType,userDTO);
    }



    @ApiOperation(value = "删除班级")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/class")
    public RootResponse deleteClass(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.deleteClass(id,userDTO);
    }
    @ApiOperation(value = "删除专业")
    @CustomResponse
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/majors")
    public RootResponse deleteMajor(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.deleteMajor(id,userDTO);
    }
    @ApiOperation(value = "删除学生")
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/students")
    @CustomResponse
    public RootResponse deleteStudent(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.deleteStudent(id,userDTO);
    }
    @ApiOperation(value = "删除教学内容")
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/teachDatas")
    @CustomResponse
    public RootResponse deleteTeachData(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.deleteTeachData(id,userDTO);
    }
    @ApiOperation(value = "删除教学类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.STUDENT,getOperationAction = OperationActionEnum.UPDATE)
    @DeleteMapping("/v1/teachDataTypes")
    @CustomResponse
    public RootResponse deleteTeachDataType(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.deleteTeachDataType(id,userDTO);
    }

    @ApiOperation(value = "查询学生信息")
    @GetMapping("/v1/students")
    @CustomResponse
    public RootResponse selectStudent(@Valid StudentPageDTO studentPageDTO) {
        return scService.selectStudent(studentPageDTO);
    }

    @ApiOperation(value = "查询所有专业")
    @GetMapping("/v1/majors")
    @CustomResponse
    public RootResponse selectAllMajor(@Valid MajorPageDTO majorPageDTO) {
        return scService.selectAllMajor(majorPageDTO);
    }


        @ApiOperation(value = "根据专业id查询班级")
    @GetMapping("/v1/classByMajorId")
        @CustomResponse
    public RootResponse selectClassByMajorId(@Valid ClassPageDTO classPageDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.selectClassByMajorId(classPageDTO);
    }
//    @ApiOperation(value = "查询学生")
//    @OperationLogAnnotation(getModuleName = ModuleEnum.PERMISSION,getOperationAction = OperationActionEnum.UPDATE)
//    @GetMapping("/v1/deleteStudent")
//    public RootResponse selectStudent(@NotBlank(message = "Id不能为空") @RequestParam(value = "id") String id) {
//        var loginUser = SecurityUtils.getLoginUser();
//        var userDTO = new LoginUserDTO();
//        userDTO.setUsername(loginUser.getUsername());
//        return scService.deleteStudent(id,userDTO);
//    }
    @ApiOperation(value = "查询教学内容")
    @OperationLogAnnotation(getModuleName = ModuleEnum.PERMISSION,getOperationAction = OperationActionEnum.UPDATE)
    @GetMapping("/v1/teachDatas")
    @CustomResponse
    public RootResponse selectTeachData(@Valid TeachDataPageDTO teachDataPageDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.selectTeachData(teachDataPageDTO,userDTO);
    }
    @ApiOperation(value = "查询教学类型")
    @OperationLogAnnotation(getModuleName = ModuleEnum.PERMISSION,getOperationAction = OperationActionEnum.UPDATE)
    @GetMapping("/v1/teachDataTypes")
    @CustomResponse
    public RootResponse selectTeachDataType(@Valid TeachDataTypePageDTO teachDataTypePageDTO) {
        var loginUser = SecurityUtils.getLoginUser();
        var userDTO = new LoginUserDTO();
        userDTO.setUsername(loginUser.getUsername());
        return scService.selectTeachDataType(teachDataTypePageDTO,userDTO);
    }



}

